<?php
//$_GET['parent']
//
//$_POST['title']
//$_POST['description']
//$_POST['parent']
//$_POST['private']

	include 'include/function.php';

	if(!isset($_user_id))redirect_error(_d('err_need_login'));
	
	if(isset($_POST['title'])){
		$addnode_title	=get_to_mysql($_POST['title']);
		$addnode_des	=get_to_mysql($_POST['description']);
		$addnode_parent	=get_to_mysql($_POST['parent']);
		$addnode_private=get_to_mysql($_POST['private']);
		if(empty($addnode_private))redirect_error('bad request');
		
		permission_check_add($_user_id,$addnode_parent);
		if($addnode_parent==get_special_page_id('Templates'))$addnode_private='view';
		easy_insert_node($addnode_title,$addnode_des,$addnode_parent,$_user_id,$addnode_private);
		redirect("shownode.php?id=$addnode_parent");
	}
	
	$addnode_parent=-1;
	if(isset($_GET['parent']))
		$addnode_parent=get_to_html($_GET['parent']);
	permission_check_add($_user_id,$addnode_parent);
	
	$page_title = $site_title . ' - ' . _d('title_addnode');
	include 'include/header.php';
	include_once 'include/form.php';

	if($addnode_parent>=0)$addnode_parent_a="<a href='shownode.php?id=$addnode_parent'>$addnode_parent</a>";
	else $addnode_parent_a='<a href="shownode.php">root</a>';
	$addnode_check_title='onChange=\'checkTitle(this,$("node_check_title_box"),"node");\'';
	draw_simple_form('post','addnode.php',array('parent'=>$addnode_parent),
		array(
			'parent'=>array('html',_d('a_parent'),$addnode_parent_a),
			'title'=>array('input',_d('a_title'),'','maxlength="200" ' . $addnode_check_title),
			'check_title'=>array('html','','<div id="node_check_title_box"></div>'),
			'description'=>array('textarea',_d('a_description'),'',' class="param_use_include param_use_end_include" '),
			'private'=>array('option',_d('a_lock'),'no','list'=>array('no'=>_d('a_no_lock'), 'yes'=>_d('sn_locked'), 'view'=>_d('sn_free_view'))),
			'submit'=>array('submit','',_d('add_submit'))
		));
	echo '<script type="text/javascript" src="include/textarea.js"></script>';
	
	include 'include/footer.php';
?>

